/******************************************************************************
	Author			: Modon
	Last Modify		: 2024/09/25
	File Name     	: mytest.c
	Description   	: 开启全过程
******************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wordexp.h>

//#include <string.h>
//#include <pthread.h>
//#include <assert.h>
//#include <time.h>

#include <plat_log.h>
#include <mpi_sys.h>
#include <ion_memmanager.h>
//#include "sample_hello.h"

int main(int argc, char* argv[])
{
	/* 1.初始化Glog库 */
    int result = 0;
    GLogConfig stGLogConfig = 
    {
        .FLAGS_logtostderr = 0,
        .FLAGS_colorlogtostderr = 1,
        .FLAGS_stderrthreshold = _GLOG_INFO,
        .FLAGS_minloglevel = _GLOG_INFO,
        .FLAGS_logbuflevel = -1,
        .FLAGS_logbufsecs = 0,
        .FLAGS_max_log_size = 1,
        .FLAGS_stop_logging_if_full_disk = 1,
    };
    strcpy(stGLogConfig.LogDir, "/tmp/log");
    strcpy(stGLogConfig.InfoLogFileNameBase, "LOG-");
    strcpy(stGLogConfig.LogFileNameExtension, "");
    log_init(argv[0], &stGLogConfig);

	/* 2.初始化MPP平台 */
	AW_MPI_SYS_Init();
	
	/* 3.查询图像对齐宽度 */
    MPP_SYS_CONF_S stSysConf;
    memset(&stSysConf, 0, sizeof(MPP_SYS_CONF_S));
    stSysConf.nAlignWidth = 32;
    AW_MPI_SYS_SetConf(&stSysConf);

	
	/* 4.申请虚拟内存 */
	unsigned int nPhyAddr = 0;
    void* pVirtAddr = NULL;
    ERRORTYPE ret = SUCCESS;
	ret = AW_MPI_SYS_MmzAlloc_Cached(&nPhyAddr, &pVirtAddr, 1024*1024);
	if(ret != SUCCESS)
    {
        aloge("fatal error! malloc fail!");
    }
    else
    {
        alogd("phyAddr[0x%x], virtAddr[%p]", nPhyAddr, pVirtAddr);
    }
	
	/* 5.获取虚拟内存实际的物理地址 */
	SYS_VIRMEM_INFO_S  pstMemInfo;
	AW_MPI_SYS_GetVirMemInfo(pVirtAddr, &pstMemInfo);
	printf("mPhyAddr = %d\n", pstMemInfo.mPhyAddr);
	
	
	/* 6.释放内存,退出MPP平台,退出Glog库 */
	AW_MPI_SYS_MmzFree(0, pVirtAddr);
	AW_MPI_SYS_Exit();
	log_quit();
	
	return 0;
}

